rdd_and_placebo_on_all_data <- function(
  data, outcome = NULL, clustervar = NULL, rdd_model,
  rdd_plot, permutation_analysis, est_rdd_power,
  winners_power, permutation_plot
) {

  # initial binding of globals
  `%>%` <- magrittr::`%>%`
  win_cabinet <- relative_date <- NULL

  # split sample into winners and losers ------------------------------------
  df_winners <- dplyr::filter(.data = data, win_cabinet == 1)
  df_losers <- dplyr::filter(.data = data, win_cabinet == 0)

  # doughnut: drop observations at the cutoff -------------------------------

  # winners
  tmp_winners_all <- df_winners %>%
    # drop observations where the running variable is 0
    dplyr::filter(relative_date  != 0)

  # losers
  tmp_losers_all <- df_losers %>%
    # drop observations where the running variable is 0
    dplyr::filter(relative_date  != 0)

  # rdd ---------------------------------------------------------------------

  # winners
  m_winners <- rdd_model(
    data = tmp_winners_all,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date"
  )

  # rdd plot winners
  p_winners <- rdd_plot(
    data = tmp_winners_all,
    model = m_winners,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date",
    title = "Electoral Winners"
  )

  # RDD power winners
  winners_power <- est_rdd_power(
    data = tmp_winners_all,
    outcome = "swd",
    running.var = "relative_date",
    cluster = "election",
    cutoff = 0,
    tau = 0.5
  )

  # losers
  m_losers <- rdd_model(
    data = tmp_losers_all,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date"
  )

  # rdd plot losers
  p_losers <- rdd_plot(
    data = tmp_losers_all,
    model = m_losers,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date",
    title = "Electoral Losers"
  )

  # RDD power losers
  losers_power <- est_rdd_power( # nolint
    data = tmp_losers_all,
    outcome = "swd",
    running.var = "relative_date",
    cluster = "election",
    cutoff = 0,
    tau = 0.5
  )


  # permutation analysis ----------------------------------------------------

  # winners
  message("Permutation analysis winners")
  m2_winners <- permutation_analysis(
    data = tmp_winners_all,
    min_day = plyr::round_any(
      x = -m_winners$bws["b", "left"],
      accuracy = 1e-0, f = floor
    ),
    max_day = plyr::round_any(
      x = m_winners$bws["b", "right"],
      accuracy = 1e-0, f = ceiling
    ),
    winner = TRUE,
    verbose = TRUE
  )

  # permutation analysis plot winners
  p2_winners <- permutation_plot(
    permutation.out = m2_winners,
    title = "Electoral Winners"
  )

  # losers
  message("Permutation analysis losers")
  m2_losers <- permutation_analysis(
    data = tmp_losers_all,
    min_day = plyr::round_any(
      x = -m_losers$bws["b", "left"],
      accuracy = 1e-0, f = floor
    ),
    max_day = plyr::round_any(
      x = m_losers$bws["b", "right"],
      accuracy = 1e-0, f = ceiling
    ),
    winner = FALSE,
    verbose = TRUE
  )

  # permutation analysis plot losers
  p2_losers <- permutation_plot(
    permutation.out = m2_losers,
    title = "Electoral Losers"
  )

  # arrange plots
  p <- ggpubr::ggarrange( # nolint
    widths = c(1, 1),
    p_winners$rdplot, p2_winners, p_losers$rdplot, p2_losers,
    ncol = 2, nrow = 2
  )

  ggplot2::ggsave(
    filename = "./figures/figure4.png",
    device = "png",
    width = 24,
    height = 19,
    units = "cm",
    dpi = 600
  )
}
